const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
module.exports = {
  entry: './src/index.tsx',
  mode: 'development',
  output: {
    filename: 'main.[contenthash:5].js',
    path: path.resolve(__dirname, 'dist'),
    clean: true,
  },
    module: {
      rules: [
        {
          test: /\.(ts|tsx)$/,
          use: 'ts-loader',
          exclude: /node_modules/,
        },
        {
          test: /\.css$/i,
          use: [MiniCssExtractPlugin.loader, "css-loader"],
        },
        {
            test: /\.(js|jsx)$/,
            exclude: /node_modules/,
            use: ['babel-loader']
        },
        {
          test: /\.(woff|woff2|eot|ttf|otf)$/i,
          type: 'asset',
        },
        {
          test: /\.(png|svg|jpg|jpeg|gif)$/i,
          type: 'asset',
        },
      ],
    },
    resolve: {
      extensions: ['.tsx', '.ts', '.js', 'jsx'],
    },
      // 其它配置项
  plugins: [
    new HtmlWebpackPlugin({
      title: 'TODO:GOGOGO', // 网页标题
      filename: 'index.html', // 生成的 HTML 文件名
      favicon: 'src/icon/logo192.png',
      template: path.resolve(__dirname, 'src/index.html'),
      minify: { // 压缩 HTML 文件
        collapseWhitespace: true,
        removeComments: true,
        removeRedundantAttributes: true,
        removeScriptTypeAttributes: true,
        removeStyleLinkTypeAttributes: true,
        useShortDoctype: true
      }
    }),
    new MiniCssExtractPlugin({filename:"[name].[contenthash:5].css"})  
  ]
};